/* 
通过Proxy+Reflect实现对象的数据劫持
*/

// 被代理的目标对象
const target = {
  name: '小浪',
  age: 22,
}

// 包含多个监视回调的处理器对象
const handler = {
  // 监视读取
  get (target, prop, receiver){
    console.log(`监视读取${prop}属性`)
    return Reflect.get (target, prop, receiver)
  },
  // 监视修改和添加
  set (target, prop, value, receiver) {
    console.log(`监视修改或添加${prop}属性`)
    return Reflect.set(target, prop, value, receiver)
  },
  // 监视删除
  deleteProperty (target, prop) {
    console.log(`监视删除${prop}属性`)
    return Reflect.deleteProperty(target, prop)
  }
}

// 创建代理对象
const proxy = new Proxy(target, handler)

// 读取
// console.log(proxy.name)
// 添加或修改
// proxy.sex = 'abc'
// proxy.name = 'Jack'

// 删除
delete proxy.name


console.log(target)